﻿using System;
using Microsoft.WindowsAzure.StorageClient;
using System.ComponentModel.DataAnnotations;

namespace LCA.Community.DAL.Model
{
    /// <summary>
    /// This class contains a phrase from a greetings board
    /// 
    /// RowKey = ID of the phrase
    /// PartitionKey = Author of the phrase
    /// </summary>
    public class Phrase : BasicDataModel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Phrase"/> class.
        /// </summary>
        public Phrase()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Phrase"/> class.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="author">The author.</param>
        /// <param name="body">The body.</param>
        public Phrase(string user,string author, string body)
        {
            RowKey = Guid.NewGuid().ToString();
            PartitionKey = user;
            Author = author;
            Date = DateTime.UtcNow;
            Body = body;
        }

        /// <summary>
        /// Gets the hash code.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return RowKey.GetHashCode();
        }
        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns><c>true</c> if both objects are equals; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            Phrase u = obj as Phrase;
            if ((System.Object)u == null)
            {
                return false;
            }

            return RowKey.Equals(u.RowKey);
        }

        /// <summary>
        /// Gets or sets the user.
        /// </summary>
        /// <value>The user.</value>
        public string User 
        {
            get
            {
                return PartitionKey;
            }
            set
            {
                PartitionKey = value;
            }
        }
        /// <summary>
        /// Gets or sets the author of the phrase.
        /// </summary>
        /// <value>
        /// The phrase's author.
        /// </value>
        public string Author { get; set; }
        /// <summary>
        /// Gets or sets the body of the phrase.
        /// </summary>
        /// <value>The phrase's body.</value>
        [Required(ErrorMessage = "Debe introducir una frase.")]
        public string Body { get; set; }
        /// <summary>
        /// Gets or sets the date of the phrase.
        /// </summary>
        /// <value>The phrase's date.</value>
        public DateTime Date { get; set; }
    }
}
